<?php
class Plugin {
  public $name = 'Pop-up explain';
  
  public $folder = 'pue';
  
  public function data($instance_id) {
    $data = new stdClass();
    $data->folder = $this->folder;
    $data->instance_id = $instance_id;
    
    require_once dirname(__FILE__) . '/../../common.inc.php';
    $cond_vals = new stdClass();
    $cond_vals->c = 't.instance_id = :v1';
    $cond_vals->v = array(':v1' => $instance_id);
    $result = DbUtils::get(DbUtils::createPdoInst(), TABLE_NAME_PREFIX_PLUGIN . $this->folder . '_config', $cond_vals, NULL, NULL, NULL, NULL, NULL);
    
    $config = new stdClass();
    if (count($result->d) > 0) {
      $config = $result->d[0];
      $data->config = $config;
    } else {
      $data->config->width = 0;
      $data->config->height = 0;
      $data->config->position = '';
      $data->config->content = '';
    }
    
    $cond_vals = new stdClass();
    $cond_vals->c = 't.instance_id = :v1';
    $cond_vals->v = array(':v1' => $instance_id);
    $result = DbUtils::get(DbUtils::createPdoInst(), TABLE_NAME_PREFIX_PLUGIN . $this->folder . '_image', $cond_vals, NULL, NULL, NULL, NULL, NULL);
    
    $data->images = $result->d;
    
    return $data;
  }
  
  public function back($data) {
    $instance_id = $data->instance_id;
   require_once dirname(__FILE__) . '/back.php';
   return MiscUtils::getPlutinJs('Pue', json_encode($data));
  }
  
  public function front($data) {
    $instance_id = $data->instance_id;
    require_once dirname(__FILE__) . '/front.php';
  }
}
?>